<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><SELECT id='companyStatus' onchange="companySearch();" style="width: 108px;" class="forminput inputstyle validatebox-text">
                <OPTION value="-1">所有状态</OPTION>
                <OPTION value="-1" disabled="disabled"> --------</OPTION>
                <OPTION value="1">显示</OPTION>
                <OPTION value="0">隐藏</OPTION>
            </SELECT>
            </td>
            <td><a href="javascript:void(0);" onclick="companyEdit();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="companyDelete();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="companyReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td>
                <div style="margin-top: -3px;">
                    <span style="line-height:30px;">注册日期</span>
                    <input id="company_start_on" type="text" style="width: 108px;" class="easyui-datebox"> </input>至
                    <input id="company_end_on" type="text" style="width: 108px;" class="easyui-datebox"> </input>
                </div>
            </td>
            <td>&nbsp;&nbsp;<input id="companyKeywords" placeholder="公司名称或编码" style="width:100px" type="text" class="forminput inputstyle"> </input></td>
            <td><a href="javascript:void(0);" onclick="companySearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con" onselectstart="return false;" style="-moz-user-select:none;">
    <table id="company"></table>
</div>
<div id="companydlg" class="easyui-dialog" title="信息框" style="width: 860px; height: 710px;" closed="true"></div>

<script>
    var companyAdd = function () {
        $("#companydlg").dialog({
            title: '添加会员',
            closed: false,
            width: 860,
            height: 710,
            cache: false,
            href: '/admin/company/add',
            modal: true,
            buttons: [{
                text: '保存',
                id: 'companyaddsubmit',
                iconCls: 'icon-ok',
            }, {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    $("#companydlg").dialog('close');
                }
            }]
        });
    };
    var companyEdit = function () {
        var row = $('#company').datagrid('getSelected');
        if (row) {
            let title = '会员编辑';
            let url = '/admin/company/edit?id=' + row.id;
            $('#rightTabs').tabs('close', title);
            addTab(title, url);
        } else {
            $.messager.alert('提示', '请先选择要编辑的记录！', 'warning');
        }
    };
    var companyDirectedit = function (id) {
        let title = '会员编辑';
        let url = '/admin/company/edit?id=' + id;
        $('#rightTabs').tabs('close', title);
        addTab(title, url);
    };
    var companyOrders = function (company_id) {
        if (typeof ($("#orders")) != 'undefined') {
            $('#rightTabs').tabs('close', '订单浏览');
        }
        addTab('订单浏览', '/admin/orders/orders?company_id=' + company_id);
    };
    var companyDelete = function () {
        var row = $('#company').datagrid('getSelections');
        var item = [];
        for (var i = 0; i < row.length; i++) {
            item.push(row[i].id);
        }
        if (row) {
            $.messager.confirm('提示', '确定批量删除选中行吗？', function (r) {
                if (r == true) {
                    $.messager.progress();
                    $.post('/admin/company/delete', {id: item}, function (data) {
                        $.messager.progress('close');
                        if (data.ret == 0) {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            companyreload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请选择要删除的行！', 'warning');
        }
    };
    var companyReload = function () {
        $("#company").datagrid('reload');
    };
    var companySearch = function () {
        var height = $(window).height() - $(".top").height() - 46;//表格高度
        var width = $(window).width() - $(".leftmenu").width() - 13;//表格高度
        $("#company").datagrid({
            title: '会员浏览',
            width: width,
            height: height,
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 20,
            pageList: [20, 25, 30, 35],
            method: 'post',
            sortName: 'created_at',
            sortOrder: 'desc',
            url: '/admin/company/get',
            queryParams: {status: $('#companyStatus').val(), keywords: $('#companyKeywords').val(), start_on: $('#company_start_on').val(), end_on: $('#company_end_on').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: true,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            rowStyler: function (index, row) {
                if (row.status == 0) {
                    return 'color:#dc324d;';
                }
            },
            columns: [[
                {field: 'code', title: '编码', width: fixWidth(10)},
                {field: 'name', title: '公司', width: fixWidth(20)},
                {
                    field: 'username', title: '账号', width: fixWidth(15), formatter: function (value, rowData, rowIndex) {
                        return rowData.members.username;
                    }
                },
                {
                    field: 'rank', title: '会员等级', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
                        return rowData.members.rank.name;
                    }
                },
                {
                    field: 'expired', title: '会员过期时间', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
                        return rowData.members.expired_at;
                    }
                },
                {
                    field: 'city', title: '地区', width: fixWidth(15), formatter: function (value, rowData, rowIndex) {
                        return rowData.province + rowData.city;
                    }
                },
                {
                    field: 'status', title: '状态', width: fixWidth(10), align: 'center', formatter: function (value, rowData, rowIndex) {
                        return rowData.status == 1 ? '显示' : '隐藏';
                    }, styler: function (value, rowData, rowIndex) {
                        switch (parseInt(rowData.status)) {
                            case 0:
                                return 'color:red;';
                            case 1:
                                return 'color:green';
                        }
                    }
                },
                {
                    field: 'audit_company', title: '公司实名认证', width: fixWidth(10), align: 'center', formatter: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_company;
                        return flag == 0 ? '未提交' : (flag == 1 ? '待审核' : (flag == 2 ? '已通过' : '未通过'));
                    }, styler: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_company;
                        switch (parseInt(flag)) {
                            case 0:
                                return 'color:grey;';
                            case 1:
                                return 'color:orange';
                            case 2:
                                return 'color:green';
                            case 3:
                                return 'color:red';
                        }
                    }
                },
                {
                    field: 'audit_members', title: '会员实名认证', width: fixWidth(10), align: 'center', formatter: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_members;
                        return flag == 0 ? '未提交' : (flag == 1 ? '待审核' : (flag == 2 ? '已通过' : '未通过'));
                    }, styler: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_members;
                        switch (parseInt(flag)) {
                            case 0:
                                return 'color:grey;';
                            case 1:
                                return 'color:orange';
                            case 2:
                                return 'color:green';
                            case 3:
                                return 'color:red';
                        }
                    }
                },
                /***
                {
                    field: 'audit_email', title: '邮箱认证', width: fixWidth(10), align: 'center', formatter: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_email;
                        return flag == 0 ? '未提交' : (flag == 1 ? '待审核' : (flag == 2 ? '已通过' : '未通过'));
                    }, styler: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_email;
                        switch (parseInt(flag)) {
                            case 0:
                                return 'color:grey;';
                            case 1:
                                return 'color:orange';
                            case 2:
                                return 'color:green';
                            case 3:
                                return 'color:red';
                        }
                    }
                },
                {
                    field: 'audit_phone', title: '手机认证', width: fixWidth(10), align: 'center', formatter: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_phone;
                        return flag == 0 ? '未提交' : (flag == 1 ? '待审核' : (flag == 2 ? '已通过' : '未通过'));
                    }, styler: function (value, rowData, rowIndex) {
                        let flag = rowData.info.audit_phone;
                        switch (parseInt(flag)) {
                            case 0:
                                return 'color:grey;';
                            case 1:
                                return 'color:orange';
                            case 2:
                                return 'color:green';
                            case 3:
                                return 'color:red';
                        }
                    }
                },
                 ***/
                {field: 'created_at', title: '注册时间', width: fixWidth(15), sortable: true},
                {
                    field: 'action', title: '操作', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
                        if (value != '') {
                            return '<a href="javascript:;" class="l-btn l-btn-small" onclick="companyDirectedit(' + rowData.id + ')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">编辑</span><span class="l-btn-icon icon-ok">&nbsp;</span></span></a>';
                        }
                    }
                },
            ]],
            onDblClickRow: function (index, field) {
                companyEdit();
            }
        });
    };
    companySearch();
</script>
